<!DOCTYPE html>
<html lang="en">
  <head>
    <title>UIEmptyState  Reference</title>
    <link rel="stylesheet" type="text/css" href="css/jazzy.css" />
    <link rel="stylesheet" type="text/css" href="css/highlight.css" />
    <meta charset="utf-8">
    <script src="js/jquery.min.js" defer></script>
    <script src="js/jazzy.js" defer></script>
    
    <script src="js/lunr.min.js" defer></script>
    <script src="js/typeahead.jquery.js" defer></script>
    <script src="js/jazzy.search.js" defer></script>
  </head>
  <body>


    <a title="UIEmptyState  Reference"></a>

    <header class="header">
      <p class="header-col header-col--primary">
        <a class="header-link" href="index.html">
          UIEmptyState Docs
        </a>
         (100% documented)
      </p>
    
      <p class="header-col--secondary">
        <form role="search" action="search.json">
          <input type="text" placeholder="Search documentation" data-typeahead>
        </form>
      </p>
    
        <p class="header-col header-col--secondary">
          <a class="header-link" href="https://github.com/luispadron/UIEmptyState">
            <img class="header-icon" src="img/gh.png"/>
            View on GitHub
          </a>
        </p>
    
    </header>

    <p class="breadcrumbs">
      <a class="breadcrumb" href="index.html">UIEmptyState Reference</a>
      <img class="carat" src="img/carat.png" />
      UIEmptyState  Reference
    </p>

    <div class="content-wrapper">
      <nav class="navigation">
        <ul class="nav-groups">
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="Classes.html">Classes</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Classes/UIEmptyStateView.html">UIEmptyStateView</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="Extensions.html">Extensions</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Extensions/UICollectionViewController.html">UICollectionViewController</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Extensions/UITableViewController.html">UITableViewController</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Extensions/UIViewController.html">UIViewController</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="Protocols.html">Protocols</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Protocols/UIEmptyStateDataSource.html">UIEmptyStateDataSource</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Protocols/UIEmptyStateDelegate.html">UIEmptyStateDelegate</a>
              </li>
            </ul>
          </li>
        </ul>
      </nav>
      <article class="main-content">

        <section class="section">
          <div class="section-content">
            
            <p><img src="https://raw.githubusercontent.com/luispadron/UIEmptyState/master/GitHubAssets/banner.jpg" alt="banner"></p>

<p><img src="https://raw.githubusercontent.com/luispadron/UIEmptyState/master/GitHubAssets/screen1.jpg" width="280"><img src="https://raw.githubusercontent.com/luispadron/UIEmptyState/master/GitHubAssets/screen2.jpg" width="280"><img src="https://raw.githubusercontent.com/luispadron/UIEmptyState/master/GitHubAssets/screen3.jpg" width="280"></p>
<h2 id='requirements' class='heading'>Requirements</h2>

<ul>
<li>Xcode 9.0 +</li>
<li>iOS 9.0 or greater</li>
</ul>
<h2 id='installation' class='heading'>Installation</h2>
<h3 id='cocoapods' class='heading'>CocoaPods</h3>

<ol>
<li>Install <a href="http://cocoapods.org">CocoaPods</a></li>
<li>Add this repo to your <code>Podfile</code></li>
</ol>
<pre class="highlight ruby"><code><span class="n">target</span> <span class="s1">'Example'</span> <span class="k">do</span>
  <span class="n">use_frameworks!</span>

  <span class="n">pod</span> <span class="s1">'UIEmptyState'</span>
<span class="k">end</span>
</code></pre>

<ol>
<li>Run <code>pod install</code></li>
<li>Open up the new <code>.xcworkspace</code> that CocoaPods generated</li>
<li>Whenever you want to use the library: <code>import UIEmptyState</code></li>
</ol>
<h3 id='carthage' class='heading'>Carthage</h3>

<ol>
<li><p>Make sure Carthage is install</p>

<p><code>brew install carthage</code></p></li>
<li><p>Add this repo to your Cartfile</p>

<p><code>github &quot;luispadron/UIEmptyState&quot;</code></p></li>
</ol>
<h3 id='manually' class='heading'>Manually</h3>

<ol>
<li>Simply download the <code>UIEmptyState</code> source files and import them into your project.</li>
</ol>
<h2 id='usage' class='heading'>Usage</h2>

<p>As long as you are using a <code>UIViewController</code> subclass you will get default conformance as well as the <code>reloadEmptyState</code> method.</p>
<pre class="highlight swift"><code><span class="c1">// No subclassing required, simply conform to the two protocols</span>
<span class="kd">class</span> <span class="kt">ViewController</span><span class="p">:</span> <span class="kt">UITableViewController</span><span class="p">,</span> <span class="kt">UIEmptyStateDataSource</span><span class="p">,</span> <span class="kt">UIEmptyStateDelegate</span> <span class="p">{</span>

    <span class="k">override</span> <span class="kd">func</span> <span class="nf">viewDidLoad</span><span class="p">()</span> <span class="p">{</span>
        <span class="k">super</span><span class="o">.</span><span class="nf">viewDidLoad</span><span class="p">()</span>
        <span class="c1">// Set the data source and delegate</span>
        <span class="k">self</span><span class="o">.</span><span class="n">emptyStateDataSource</span> <span class="o">=</span> <span class="k">self</span>
        <span class="k">self</span><span class="o">.</span><span class="n">emptyStateDelegate</span> <span class="o">=</span> <span class="k">self</span>
        <span class="c1">// Optionally remove seperator lines from empty cells</span>
        <span class="k">self</span><span class="o">.</span><span class="n">tableView</span><span class="o">.</span><span class="n">tableFooterView</span> <span class="o">=</span> <span class="kt">UIView</span><span class="p">(</span><span class="nv">frame</span><span class="p">:</span> <span class="kt">CGRect</span><span class="o">.</span><span class="n">zero</span><span class="p">)</span>
   <span class="p">}</span>

   <span class="k">override</span> <span class="kd">func</span> <span class="nf">viewDidAppear</span><span class="p">(</span><span class="n">_</span> <span class="nv">animated</span><span class="p">:</span> <span class="kt">Bool</span><span class="p">)</span> <span class="p">{</span>
    <span class="k">super</span><span class="o">.</span><span class="nf">viewDidAppear</span><span class="p">(</span><span class="n">animated</span><span class="p">)</span>
    <span class="c1">// Set the initial state of the tableview, called here because cells should be done loading by now</span>
    <span class="c1">// Number of cells are used to determine if the view should be shown or not</span>
    <span class="k">self</span><span class="o">.</span><span class="nf">reloadEmptyState</span><span class="p">()</span>
   <span class="p">}</span>
<span class="p">}</span>
</code></pre>

<p>Whenever you need to reload the empty state view for example, on data changes to your table view source, make sure to call <code>self.reloadEmptyState()</code> if inside a <code>UITableViewController</code> or <code>UICollectionViewController</code>. If inside a regular <code>UIViewController</code> make sure to call the appropriate <code>reloadEmptyStateForTableView(_:)</code> or <code>reloadEmptyStateForCollectionView(_:)</code> methods.</p>

<p>Example: </p>
<pre class="highlight swift"><code><span class="c1">// Inside a UITableViewController subclass</span>

<span class="kd">func</span> <span class="nf">foo</span><span class="p">()</span> <span class="p">{</span>
    <span class="c1">// My data has changed here, I want to my tableview, </span>
    <span class="c1">// and in case I no longer have data (user deleted, etc) also reload empty view</span>
    <span class="k">self</span><span class="o">.</span><span class="n">tableView</span><span class="o">.</span><span class="nf">reloadData</span><span class="p">()</span>
    <span class="c1">// Reload empty view as well</span>
    <span class="k">self</span><span class="o">.</span><span class="nf">reloadEmptyState</span><span class="p">()</span>
<span class="p">}</span>

<span class="kd">func</span> <span class="nf">deleteFoo</span><span class="p">()</span> <span class="p">{</span>
    <span class="c1">// This works too, just call after end updates</span>
    <span class="n">tableView</span><span class="o">.</span><span class="nf">beginUpdates</span><span class="p">()</span>
    <span class="n">fooSource</span><span class="o">.</span><span class="nf">remove</span><span class="p">(</span><span class="nv">at</span><span class="p">:</span> <span class="n">indexPath</span><span class="o">.</span><span class="n">row</span><span class="p">)</span>
    <span class="n">tableView</span><span class="o">.</span><span class="nf">deleteRows</span><span class="p">(</span><span class="nv">at</span><span class="p">:</span> <span class="p">[</span><span class="n">indexPath</span><span class="p">],</span> <span class="nv">with</span><span class="p">:</span> <span class="o">.</span><span class="n">automatic</span><span class="p">)</span>
    <span class="n">tableView</span><span class="o">.</span><span class="nf">endUpdates</span><span class="p">()</span>
    <span class="c1">// Call reload of empty state </span>
    <span class="k">self</span><span class="o">.</span><span class="nf">reloadEmptyState</span><span class="p">()</span>
<span class="p">}</span>
</code></pre>

<p>If you need more help take a look at the example project here (Pokemon nerds, will like it): <a href="https://github.com/luispadron/UIEmptyState/tree/master/UIEmptyStateExample">Example</a></p>
<h2 id='documentation' class='heading'>Documentation</h2>
<h4 id='a-href-http-htmlpreview-github-io-https-github-com-luispadron-uiemptystate-blob-master-docs-index-html-read-the-full-documentation-here-a' class='heading'><a href="http://htmlpreview.github.io/?https://github.com/luispadron/UIEmptyState/blob/master/docs/index.html">Read the full documentation here</a></h4>
<h2 id='example-project' class='heading'>Example Project</h2>

<ol>
<li>Clone this repo</li>
<li>Change directory into <code>Example</code></li>
<li>Run <code>pod install</code></li>
</ol>
<h2 id='license-mit' class='heading'>License (MIT)</h2>
<pre class="highlight plaintext"><code>Copyright (c) 2017 Luis Padron

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
</code></pre>

          </div>
        </section>


      </article>
    </div>
    <section class="footer">
      <p>&copy; 2018 <a class="link" href="https://luispadron.com" target="_blank" rel="external">Luis</a>. All rights reserved. (Last updated: 2018-04-09)</p>
      <p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.9.1</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
    </section>
  </body>
</div>
</html>
